#!/usr/bin/perl
# use Data::Dumper;

# 本程序，只针对 B C 两个端口
# 默认只 500 速度运行 2 秒
# 执行运行方式比如：run-to-abs-pos，run-to-rel-pos，run-timed，run-direct，run-forever

%MOTOR_PATH;  # Motor Mapping  "A" => "Dirver Path"

getMotorInfo();


`echo -100 > $MOTOR_PATH{B}/speed_sp`;
`echo 100 > $MOTOR_PATH{C}/speed_sp`;
`echo 2000 > $MOTOR_PATH{B}/time_sp`;
`echo 2000 > $MOTOR_PATH{C}/time_sp`;
`echo run-timed > $MOTOR_PATH{B}/command`;
`echo run-timed > $MOTOR_PATH{C}/command`;

	
#  获得Motor Mapping
sub getMotorInfo{
	for($i=0;$i<5;$i++){
		my $add="/sys/class/tacho-motor/motor$i/address";
		if(-e $add){
			my $content=`cat $add`;
			(my $port)=$content=~/out((A|B|C|D))/;
			$MOTOR_PATH{$port}="/sys/class/tacho-motor/motor$i";
		}
	}
}

